Ext.define('AM.view.PersonPlanView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.personPlanView',
		initComponent: function(){
		Ext.apply(this,{
				store : 'MyPlanStore',
				columnLines:true,
//				selModel : Ext.create('Ext.selection.CheckboxModel'),
				selModel: {
			        injectCheckbox: 0,
			        mode: "SIMPLE"     //"SINGLE"/"SIMPLE"/"MULTI"
			     
		   		 },
		   		selType: "checkboxmodel",
		    	dockedItems: [
		    		{
		        xtype: 'pagingtoolbar',
		        dock: 'bottom',
		        store : 'MyPlanStore',
		        displayInfo: true
		    	},{
			     dock: 'top',
			     xtype: 'toolbar',
			     items: [
			     '科室：',{
							 xtype : "combobox",
							 allowBlank:false,
				             emptyText:'请选择科室',
							 selectOnFocus:true,
							 forceSelection: true,
					         queryMode: 'local',
							 labelAlign :"right",
							 name: 'department',
							 store :"TargetDepartStore",
							 displayField: 'name',
		    				 valueField: 'id',
						     listeners:{   
										   select:function(combo, record,index){
													 try{
														 var parent=Ext.getCmp('detailpost');
														 parent.clearValue();
														 parent.store.load({params:{param:this.value}});
														 }
											          catch(ex){
														 Ext.MessageBox.alert("错误","数据加载失败。");
														 }
											},
											afterrender:function(thiz){
											 		//alert(Number(deptID));
						 	                                       if(Number(deptID)>0){
						 	                                       
						                                            thiz.setValue(Number(deptID));
						                                            thiz.setReadOnly(true);
						                                            var parent=Ext.getCmp('detailpost');
														            parent.clearValue();
														            parent.store.load({params:{param:this.value}});
											}
											}
								}
			     },'-',' 工作岗位: ', {
			     	 xtype : "combobox",
				     allowBlank:false,
				     emptyText:'请选择岗位',
					 selectOnFocus:true,
				     forceSelection: true,
					 queryMode: 'local',
					 labelAlign :"right",
					 name: 'post',
					 store :"PostStore",
					 displayField: 'name',
		    		 valueField: 'id',
					 id:'detailpost'
			      },{
			      	 xtype : "datefield",
					 fieldLabel: '日期',
					  labelAlign :"right",
					 labelWidth:60,
					 format:'Y-m-d',
					 id:'plantjob_999'
			      },'-', {
			            xtype: 'button',
			            text: '搜索',
			            icon : 'Ext/restful/images/find.png',
			            margin: '0 0 0 5',
			            handler: function () {
			                 var post1 = Ext.getCmp('detailpost').getValue(); //获取文本框值
			                 var grid=this.ownerCt.ownerCt;
		//	                 Ext.getCmp('personPlanView').getStore().on('beforeload', function (store, options) {
			                 grid.getStore().on('beforeload', function (store, options) {
			                                    var new_params = {post1:post1};
			                                    Ext.apply(store.proxy.extraParams, new_params);
			                                    });
		//	                  Ext.getCmp('personPlanView').getStore().reload();
			                  grid.getStore().reload();
			                }
			        }]
		    }],
				columns: [	
		//			        {text: '序号', xtype: 'rownumberer',width:50,align:'center'},
					        {text: '序号', dataIndex: 'id',width:50,align:'center'},
					        { text: '名称', dataIndex: 'name', width:160,align:'center'},
					        { text: '内容', dataIndex: 'adcontent', width:580,align:'center'}
					     ],
					   tbar: [
							  { xtype: 'button', text: '保存计划',handler: savemyplan,icon: 'Ext/restful/images/add.png'
							  }
							   
							]
								});
			   this.callParent(arguments);
  	}
		
})

function savemyplan(){
		var grid=this.ownerCt.ownerCt;
		var selections = grid.getSelectionModel().getSelection();
		var date= Ext.getCmp('plantjob_999').getValue();
	    var creatdate =Ext.util.Format.date(date, 'Y-m-d');
			if(selections){
					if(selections.length==0){
							Ext.MessageBox.alert("提示","请检查是否选中行！");
							}else{   
									var names=[]; var adcontents=[];
									for(var i=0;i<selections.length;i++){
										var record = selections[i];
										names.push(record.get("name"));
										adcontents.push(record.get("adcontent"));
									  }
										Ext.Ajax.request({
										url : 'jobDetail_addplanjob',
										success : function() {
											 Ext.MessageBox.alert("提示", "保存成功！");
//										     grid.getStore().reload();	
											 grid.getSelectionModel().deselectAll();//去除选择
											 Ext.getCmp('weekProcedureView').getStore().reload();	
											},
											failure : function() {
												Ext.MessageBox.alert("提示", "保存失败！");
											},
											params : {
												    names:names,
												    adcontents:adcontents,
												    creatdate:creatdate
												    
												}
									});	
							}
					}	
}
 

	